<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('房屋分配标签')" />
</head>
<body>
    <div class="main-content">
        <form id="form-user-add" class="form-horizontal">
            <h4 class="form-header h4">房屋基本信息</h4>
            <div class="row">
            	<div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">房屋名称：</label>
                        <div class="col-sm-8">
                            <input name="name" class="form-control" type="text" disabled th:value="${house.name}">
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">房屋ID：</label>
                        <div class="col-sm-8">
                            <input id="houseId" name="houseId" class="form-control" type="text" disabled th:value="${house.houseId}">
                        </div>
                    </div>
                </div>
            </div>

            <h4 class="form-header h4">分配标签</h4>
            <div class="row">
                <div class="col-sm-12">
                    <div class="col-sm-12 select-table table-striped">
					    <table id="bootstrap-table"></table>
					</div>
                </div>
            </div>
        </form>
    </div>
      
    <div class="row">
        <div class="col-sm-offset-5 col-sm-10">
            <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
            <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
        </div>
    </div>
	<th:block th:include="include :: footer" />
	<script th:inline="javascript">
	    var prefix = ctx + "admin/house/authTag";
	    var tags = [[${tags}]]
	    
	    $(function() {
		    var options = {
		        data: tags,
		        sidePagination: "client",
		        showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                clickToSelect: true,
                maintainSelected: true,
		        columns: [{
		            checkbox: true,
		            formatter:function (value, row, index) {
		            	if($.common.isEmpty(value)) {
		            		return { checked: row.flag };
		            	} else {
		            		return { checked: value }
		            	}
		            }
		        },
		        {
		            field: 'tagId',
		            title: '标签编号'
		        },
		        {
		            field: 'name',
		            title: '标签名称',
                    formatter: function (value, row, index) {
                        return '<i class="fa fa-tag"></i> '+row.name
                    }
		        },
                {
                    field: 'prior',
                    title: '标签优先级',
                    align: 'center',
                    formatter: function (value, row, index) {
                        if (row.prior == 1) {
                            return '<strong>高级</strong>';
                        } else if (row.prior == 2){
                            return '<strong>中等</strong>';
                        } else if (row.prior == 3){
                            return '<strong>普通</strong>';
                        }
                    },
                    cellStyle: function(value,row,index){
                        if (row.prior == 1) {
                            return {
                                css:{
                                    'color':'#510080'
                                }
                            };
                        } else if (row.prior == 2){
                            return {
                                css:{
                                    'color':'#ec9f12'
                                }
                            };
                        } else if (row.prior == 3){
                            return {
                                css:{
                                    'color':'#008018'
                                }
                            };
                        }
                    }
                },]
		    };
		    $.table.init(options);
		});
	    
	    /* 添加标签-提交 */
        function submitHandler(index, layero){
        	var rows = $.table.selectFirstColumns();
        	var data = { "houseId": $("#houseId").val(), "tagIds": rows.join() };
            if(rows.length > 12){
                $.modal.alertWarning("选择标签不能超过15条");
                return;
            }
			$.operate.saveTab(prefix + "/insertAuthTag", data);
        }
    </script>
</body>
</html>